home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / targ-cpu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-26  |  9.7 KB  |  303 lines

  1. /* tc-i386.h -- Header file for tc-i386.c
  2.    Copyright (C) 1989, 1992 Free Software Foundation.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef TC_I386
  21. #define TC_I386 1
  22.  
  23. #ifdef BFD_ASSEMBLER
  24.  
  25. #define TARGET_ARCH        bfd_arch_i386
  26. #define TARGET_BYTES_BIG_ENDIAN    0
  27.  
  28. #ifdef OBJ_AOUT
  29. #ifdef TE_386BSD
  30. #define TARGET_FORMAT        "a.out-i386-bsd"
  31. #endif
  32. #ifdef TE_LINUX
  33. #define TARGET_FORMAT        "a.out-i386-linux"
  34. #endif
  35. #ifdef TE_GO32
  36. /* #define TARGET_FORMAT        "a.out-i386-go32" */
  37. #define TARGET_FORMAT        "coff-go32"
  38. #endif
  39. #ifndef TARGET_FORMAT
  40. #define TARGET_FORMAT        "a.out-i386"
  41. #endif
  42. #endif /* OBJ_AOUT */
  43.  
  44. #ifdef OBJ_ELF
  45. #define TARGET_FORMAT        "elf32-i386"
  46. #endif
  47.  
  48. #else /* ! BFD_ASSEMBLER */
  49.  
  50. /* COFF STUFF */
  51.  
  52. #define COFF_MAGIC I386MAGIC
  53. #define BFD_ARCH bfd_arch_i386
  54. #define COFF_FLAGS F_AR32WR
  55. #define TC_COUNT_RELOC(x) ((x)->fx_addsy /* ||(x)->fx_subsy||(x)->fx_offset */)
  56. #define TC_COFF_FIX2RTYPE(fixP) tc_coff_fix2rtype(fixP)
  57. #define TC_COFF_SIZEMACHDEP(frag) tc_coff_sizemachdep(frag)
  58. #define SUB_SEGMENT_ALIGN(SEG) 2
  59.  
  60.  
  61. #define AOUT_MACHTYPE /* 100 */ 0
  62. #undef REVERSE_SORT_RELOCS
  63.  
  64. #endif /* ! BFD_ASSEMBLER */
  65.  
  66. #define NO_RELOC 0
  67. #define tc_coff_symbol_emit_hook(a)    ;    /* not used */
  68.  
  69. #if !defined (TE_386BSD) && !defined (TE_LINUX) && !defined(TE_GO32)
  70. /* Local labels starts with .L */
  71. #define DOT_LABEL_PREFIX
  72. #endif
  73. #define LOCAL_LABELS_FB
  74.  
  75. #define tc_aout_pre_write_hook(x)    {;}    /* not used */
  76. #define tc_crawl_symbol_chain(a)    {;}    /* not used */
  77. #define tc_headers_hook(a)        {;}    /* not used */
  78.  
  79. #define MAX_OPERANDS 3        /* max operands per insn */
  80. #define MAX_PREFIXES 4        /* max prefixes per opcode */
  81. #define MAX_IMMEDIATE_OPERANDS 2/* max immediates per insn */
  82. #define MAX_MEMORY_OPERANDS 2    /* max memory ref per insn
  83.                  * lcall uses 2
  84.                  */
  85. /* we define the syntax here (modulo base,index,scale syntax) */
  86. #define REGISTER_PREFIX '%'
  87. #define IMMEDIATE_PREFIX '$'
  88. #define ABSOLUTE_PREFIX '*'
  89. #define PREFIX_SEPERATOR '/'
  90.  
  91. #define TWO_BYTE_OPCODE_ESCAPE 0x0f
  92. #define NOP_OPCODE 0x90
  93.  
  94. /* register numbers */
  95. #define EBP_REG_NUM 5
  96. #define ESP_REG_NUM 4
  97.  
  98. /* modrm_byte.regmem for twobyte escape */
  99. #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
  100. /* index_base_byte.index for no index register addressing */
  101. #define NO_INDEX_REGISTER ESP_REG_NUM
  102. /* index_base_byte.base for no base register addressing */
  103. #define NO_BASE_REGISTER EBP_REG_NUM
  104.  
  105. /* these are the att as opcode suffixes, making movl --> mov, for example */
  106. #define DWORD_OPCODE_SUFFIX 'l'
  107. #define WORD_OPCODE_SUFFIX  'w'
  108. #define BYTE_OPCODE_SUFFIX  'b'
  109.  
  110. /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
  111. #define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
  112. #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
  113.  
  114. #define END_OF_INSN '\0'
  115.  
  116. /*
  117.   When an operand is read in it is classified by its type.  This type includes
  118.   all the possible ways an operand can be used.  Thus, '%eax' is both 'register
  119.   # 0' and 'The Accumulator'.  In our language this is expressed by OR'ing
  120.   'Reg32' (any 32 bit register) and 'Acc' (the accumulator).
  121.   Operands are classified so that we can match given operand types with
  122.   the opcode table in i386-opcode.h.
  123.   */
  124. #define Unknown 0x0
  125. /* register */
  126. #define Reg8    0x1        /* 8 bit reg */
  127. #define Reg16   0x2        /* 16 bit reg */
  128. #define Reg32   0x4        /* 32 bit reg */
  129. #define Reg     (Reg8|Reg16|Reg32)    /* gen'l register */
  130. #define WordReg (Reg16|Reg32)    /* for push/pop operands */
  131. /* immediate */
  132. #define Imm8    0x8        /* 8 bit immediate */
  133. #define Imm8S    0x10        /* 8 bit immediate sign extended */
  134. #define Imm16   0x20        /* 16 bit immediate */
  135. #define Imm32   0x40        /* 32 bit immediate */
  136. #define Imm1    0x80        /* 1 bit immediate */
  137. #define ImmUnknown Imm32    /* for unknown expressions */
  138. #define Imm     (Imm8|Imm8S|Imm16|Imm32)    /* gen'l immediate */
  139. /* memory */
  140. #define Disp8   0x200        /* 8 bit displacement (for jumps) */
  141. #define Disp16  0x400        /* 16 bit displacement */
  142. #define Disp32  0x800        /* 32 bit displacement */
  143. #define Disp    (Disp8|Disp16|Disp32)    /* General displacement */
  144. #define DispUnknown Disp32    /* for unknown size displacements */
  145. #define Mem8    0x1000
  146. #define Mem16   0x2000
  147. #define Mem32   0x4000
  148. #define BaseIndex 0x8000
  149. #define Mem     (Disp|Mem8|Mem16|Mem32|BaseIndex)    /* General memory */
  150. #define WordMem   (Mem16|Mem32|Disp|BaseIndex)
  151. #define ByteMem   (Mem8|Disp|BaseIndex)
  152. /* specials */
  153. #define InOutPortReg 0x10000    /* register to hold in/out port addr = dx */
  154. #define ShiftCount 0x20000    /* register to hold shift cound = cl */
  155. #define Control 0x40000        /* Control register */
  156. #define Debug   0x80000        /* Debug register */
  157. #define Test    0x100000    /* Test register */
  158. #define FloatReg 0x200000    /* Float register */
  159. #define FloatAcc 0x400000    /* Float stack top %st(0) */
  160. #define SReg2   0x800000    /* 2 bit segment register */
  161. #define SReg3   0x1000000    /* 3 bit segment register */
  162. #define Acc     0x2000000    /* Accumulator %al or %ax or %eax */
  163. #define ImplicitRegister (InOutPortReg|ShiftCount|Acc|FloatAcc)
  164. #define JumpAbsolute 0x4000000
  165. #define Abs8  0x08000000
  166. #define Abs16 0x10000000
  167. #define Abs32 0x20000000
  168. #define Abs (Abs8|Abs16|Abs32)
  169.  
  170. #define Byte (Reg8|Imm8|Imm8S)
  171. #define Word (Reg16|Imm16)
  172. #define DWord (Reg32|Imm32)
  173.  
  174. #define SMALLEST_DISP_TYPE(num) \
  175.     fits_in_signed_byte(num) ? (Disp8|Disp32|Abs8|Abs32) : (Disp32|Abs32)
  176.  
  177. typedef struct
  178.   {
  179.     /* instruction name sans width suffix ("mov" for movl insns) */
  180.     char *name;
  181.  
  182.     /* how many operands */
  183.     unsigned int operands;
  184.  
  185.     /* base_opcode is the fundamental opcode byte with a optional prefix(es). */
  186.     unsigned int base_opcode;
  187.  
  188.     /* extension_opcode is the 3 bit extension for group <n> insns.
  189.        If this template has no extension opcode (the usual case) use None */
  190.     unsigned char extension_opcode;
  191. #define None 0xff        /* If no extension_opcode is possible. */
  192.  
  193.     /* the bits in opcode_modifier are used to generate the final opcode from
  194.        the base_opcode.  These bits also are used to detect alternate forms of
  195.        the same instruction */
  196.     unsigned int opcode_modifier;
  197.  
  198.     /* opcode_modifier bits: */
  199. #define W        0x1        /* set if operands are words or dwords */
  200. #define D        0x2        /* D = 0 if Reg --> Regmem; D = 1 if Regmem --> Reg */
  201.     /* direction flag for floating insns:  MUST BE 0x400 */
  202. #define FloatD 0x400
  203.     /* shorthand */
  204. #define DW (D|W)
  205. #define ShortForm 0x10        /* register is in low 3 bits of opcode */
  206. #define ShortFormW 0x20        /* ShortForm and W bit is 0x8 */
  207. #define Seg2ShortForm 0x40    /* encoding of load segment reg insns */
  208. #define Seg3ShortForm 0x80    /* fs/gs segment register insns. */
  209. #define Jump 0x100        /* special case for jump insns. */
  210. #define JumpInterSegment 0x200    /* special case for intersegment leaps/calls */
  211.     /* 0x400 CANNOT BE USED since it's already used by FloatD above */
  212. #define DONT_USE 0x400
  213. #define NoModrm 0x800
  214. #define Modrm 0x1000
  215. #define imulKludge 0x2000
  216. #define JumpByte 0x4000
  217. #define JumpDword 0x8000
  218. #define ReverseRegRegmem 0x10000
  219.  
  220.     /* (opcode_modifier & COMES_IN_ALL_SIZES) is true if the
  221.        instuction comes in byte, word, and dword sizes and is encoded into
  222.        machine code in the canonical way. */
  223. #define COMES_IN_ALL_SIZES (W)
  224.  
  225.     /* (opcode_modifier & COMES_IN_BOTH_DIRECTIONS) indicates that the
  226.        source and destination operands can be reversed by setting either
  227.        the D (for integer insns) or the FloatD (for floating insns) bit
  228.        in base_opcode. */
  229. #define COMES_IN_BOTH_DIRECTIONS (D|FloatD)
  230.  
  231.     /* operand_types[i] describes the type of operand i.  This is made
  232.        by OR'ing together all of the possible type masks.  (e.g.
  233.        'operand_types[i] = Reg|Imm' specifies that operand i can be
  234.        either a register or an immediate operand */
  235.     unsigned int operand_types[3];
  236.   }
  237.  
  238. template;
  239.  
  240. /*
  241.   'templates' is for grouping together 'template' structures for opcodes
  242.   of the same name.  This is only used for storing the insns in the grand
  243.   ole hash table of insns.
  244.   The templates themselves start at START and range up to (but not including)
  245.   END.
  246.   */
  247. typedef struct
  248.   {
  249.     template *start;
  250.     template *end;
  251.   } templates;
  252.  
  253. /* these are for register name --> number & type hash lookup */
  254. typedef struct
  255.   {
  256.     char *reg_name;
  257.     unsigned int reg_type;
  258.     unsigned int reg_num;
  259.   }
  260.  
  261. reg_entry;
  262.  
  263. typedef struct
  264.   {
  265.     char *seg_name;
  266.     unsigned int seg_prefix;
  267.   }
  268.  
  269. seg_entry;
  270.  
  271. /* these are for prefix name --> prefix code hash lookup */
  272. typedef struct
  273.   {
  274.     char *prefix_name;
  275.     unsigned char prefix_code;
  276.   }
  277.  
  278. prefix_entry;
  279.  
  280. /* 386 operand encoding bytes:  see 386 book for details of this. */
  281. typedef struct
  282.   {
  283.     unsigned regmem:3;        /* codes register or memory operand */
  284.     unsigned reg:3;        /* codes register operand (or extended opcode) */
  285.     unsigned mode:2;        /* how to interpret regmem & reg */
  286.   }
  287.  
  288. modrm_byte;
  289.  
  290. /* 386 opcode byte to code indirect addressing. */
  291. typedef struct
  292.   {
  293.     unsigned base:3;
  294.     unsigned index:3;
  295.     unsigned scale:2;
  296.   }
  297.  
  298. base_index_byte;
  299.  
  300. #endif /* TC_I386 */
  301.  
  302. /* end of tc-i386.h */
  303.